package com.cdp.zwy.background_manager_back.controller;

import com.cdp.zwy.background_manager_back.common.Result;
import com.cdp.zwy.background_manager_back.domain.Admin;
import com.cdp.zwy.background_manager_back.mapper.AdminMapper;
import com.cdp.zwy.background_manager_back.service.AdminService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2025/3/27 16:17
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Resource
    private AdminService adminService;

    @GetMapping("/selectAll")
    public Result selectAll(Admin admin){
        List<Admin> admins = adminService.selectAll(admin);
        return Result.success(admins);
    }
//    路径传参
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id){
        Admin admin = adminService.selectById(id);
        return Result.success(admin);
    }
////url传参
//    @GetMapping("/selectOne")
//    public Result selectByName(@RequestParam int id){
//        Admin admin = adminService.selectById(id);
//        return Result.success(admin);
//    }
//    @GetMapping("/selectList")
//    public Result selectList(Admin admin){
//        List<Admin> admins = adminService.selectList(admin);
//        return Result.success(admins);
//    }

    /**
     * 分页查询
     * @param pageNum 当前页码
     * @param pageSize 每页显示条数
     */
    @GetMapping("/selectPage")
    public Result selectPage(Admin admin,
            @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize
                             ) {
        PageInfo<Admin> pageInfo = adminService.selectPage(admin,pageNum, pageSize);
        return Result.success(pageInfo);

    }
    @PostMapping("/add")
    public Result add(@RequestBody Admin admin){
        int i = adminService.add(admin);
        return Result.success(i);
    }
    @PutMapping("/update")
    public Result update(@RequestBody Admin admin){
        int i = adminService.update(admin);
        return Result.success(i);
    }
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        int i = adminService.delete(id);
        return Result.success(i);
    }


}
